#include "key_task.h"

uint8_t Key_Val,Key_Down,Key_Up,Key_Old;

void key_proc(void)//按键检测程序
{
	//按键扫描部分//
	Key_Val=Key_Read();
	Key_Down=Key_Val & (Key_Old ^ Key_Val);
	Key_Up=~Key_Val & (Key_Old ^ Key_Val);
	Key_Old=Key_Val;

    switch(Key_Down)
    {
        case 1:
            beep_key_flag = 1;
            beep_tick = TIL_GetTick();
            if(++System_Mode == 4)
            {
                System_Mode = 0;
            }
            break;
        case 2:
            Motor_On();
            Angle_PID_Flag = 1;
            Speed_midset = Speed_ZX;
            if(System_Mode == 0 | System_Mode == 1)
            {
                yaw_detect = yaw_val;
            }
            else 
            {
                yaw_detect = yaw_val - LX_3_IMU_ANGEL_1;
            }

            Motor_flag = 1;
            break;
        case 3:
            Motor_flag = 0;
            Serial_JY61P_Zero_Yaw();
            Motor_Off();            
        break;
    }

    if(Key_Down != 0){
        auto_menu_handle_key(Key_Down + 1);
    }
}